<%--                                                                       --%>
<%-- Copyright (c) 2003-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript">

    
 function doStartInstance(thisForm, ctx) {
 
    var mapping;
    if( thisForm.processName.value == 'FulfillmentProcess')
       mapping = '/demand/fulfillmentInstances.do';
    else if( thisForm.processName.value == 'SettlementProcess')
       mapping = '/demand/settlementInstances.do';
    else if( thisForm.processName.value == 'OrderFlowProcess')
       mapping = '/demand/orderflowInstances.do';
          
    url = ctx + '/cm/startWebflow.do?' 
          + 'wantCtx=false&container=/demand/pageFlowContainer.do'
          + '&ssp_process_oid=' + thisForm.processOid.value  
          + '&exitURL=' 
          +  mapping 
          + '&reqParam=_process_content';

    location.href = url; 
    return false;
 }
 
 function confirmStop(){
    return confirm("<bean:message bundle="ss" key="demand.alert.stopInstance" />");
}
 
</script>
  
<% 
  java.util.HashMap map = new java.util.HashMap();
  String procOid = request.getParameter("processOid"); 
  if (procOid != null && procOid.length() > 0) {
    map.put("processOid", procOid);
  }
  else {
    map.put("processOid", "-1");
  }
  pageContext.setAttribute("pagetabParam", map, PageContext.PAGE_SCOPE);
%>

<c:set var="stopImg">
<img src="<%= ctxPath %>/demand/images/icons/icon_stop.gif" width="15" 
   height="15" border="0" class="actionIcon" 
   alt="<bean-el:message key="demand.image.alt.stop" bundle="ss"/>" 
   title="<bean-el:message key="demand.image.alt.stop" bundle="ss"/>">
</c:set>

<html-el:form action="/demand/daemonInstanceList.do">

<html-el:hidden property="processOid" />
<html-el:hidden property="processName" />
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr> 
    <td valign="top" width="100%">
      <div class="pageTitle"><c:out value="${daemonInstanceListView.map.name}"/></div>
      <div class="errorMessage"><html-el:errors bundle="ss"/></div>
      <%@include file="/mc/common/pagetab.jsp" %>
      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="demand.order.label.instances" bundle="ss"/> - 
        <c:out value="${daemonInstanceListView.map.numInstances}"/> 
        <bean-el:message key="demand.order.label.found" bundle="ss"/>        
        </span>
        <span class="right">
       	  <input type="button" class="inputButton" value="<bean:message key="button.instance.start" bundle="ss"/>" 
         	onClick='doStartInstance(this.form, "<%=request.getContextPath()%>")'>
        </span>
      </div> 
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Process instance list" width="100%">
        <tr class="listHeader">
          <th valign="top" id="processInstanceName" align="left">
            <bean-el:message key="demand.order.label.instanceName" bundle="ss"/>
          </th>
          <th valign="top" id="status" align="left">
	  	    <bean-el:message key="demand.label.status" bundle="ss"/>
          </th>
          <th valign="top" id="startDate"  align="left">
	              <bean-el:message key="demand.order.label.startDate" bundle="ss"/>
          </th>
          <th valign="top" id="launchUser" align="left">
	     <bean-el:message key="demand.order.label.launchUser" bundle="ss"/>
          </th>          
          <th valign="top" id="stop" align="left" nowrap>
            <bean-el:message key="demand.label.stop" bundle="ss"/>
          </th>
        </tr>
        <logic:empty name="daemonInstanceListView" property="instances">
          <tr class="listEven">
            <td align="center" colspan="6">
              <bean-el:message key="demand.order.label.noInstance" bundle="ss"/>
            </td>
          </tr>
        </logic:empty>
        <logic:notEmpty name="daemonInstanceListView" property="instances">
          <logic:iterate id="instance" name="daemonInstanceListView" property="instances" indexId="i">
            <tr class="<%=i.intValue() % 2 == 0 ? "listEven" : "listOdd" %>">
              <td valign="top"  headers="processInstanceName">
                <html-el:link page="/bp/processInstance.do" paramId="instanceOid" paramName="instance" paramProperty="oid">
                  <c:out value="${instance.map.customId}"/>
                </html-el:link>
              </td>
              <td valign="top" headers="status">
	      	      	 <bean:write name="instance" property="daemonState" />
              </td>
              <td valign="top" headers="startDate">
	                      <bean:write name="instance" property="startDate" formatKey="format.datetime.short" bundle="mc.messages"/>
              </td>
              <td valign="top" headers="launchUser">
	          <bean:write name="instance" property="launchUser" />
              </td>              
              <td valign="top" nowrap align="left" headers="stop">
              	   <c:url var="stopUrl" value="/demand/daemonInstanceStop.do">
	      		<c:param name="instanceOid" value="${instance.map.oid}"/>
	      		<c:param name="processName" value="${daemonInstanceListForm.map.processName}"/>
		   </c:url>
                   <a href='<c:out value="${stopUrl}"/>' onclick="return confirmStop();" >
		        <c:out value='${stopImg}' escapeXml="false"/>
                    </a>
              </td>
            </tr>
          </logic:iterate>
        </logic:notEmpty>
      </table>
      <logic:notEmpty name="daemonInstanceListView" property="instances">
          <%@ include file="/mc/common/pager.jsp" %>
      </logic:notEmpty>
    </td>
  </tr>
</table>
</html-el:form>

